﻿using eFatura.Utility;
using Extensions;
using System;
using System.Data;
using DevExpress.XtraEditors.Controls;

namespace eFatura
{
    public partial class SorumluAta : XPopupForm
    {
        int PayFlexId;

        public SorumluAta(int PayFlexId)
        {
            InitializeComponent();
            this.PayFlexId = PayFlexId;
        }
      

        private void Cevap_Load(object sender, EventArgs e)
        {
            cmbTip.SelectedIndexChanged += cmbTip_SelectedIndexChanged;
            Shown += Cevap_Shown;
            
            cmbTip.SelectedIndex = 0;

            DataTable table = gle.Properties.DataSource as DataTable;
            gle.EditValue = table.Rows[0][0].ToIntNN();
            
        }

        void Cevap_Shown(object sender, EventArgs e)
        {
            btnAta.Focus();
        }

        void cmbTip_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (cmbTip.Text)
            {
                case "Departman": gle.Properties.Assign(RepositoryManager.Departman); break;
                case "Kullanıcı": gle.Properties.Assign(RepositoryManager.Kullanici); break;
            }
            DataTable table = gle.Properties.DataSource as DataTable;
            gle.EditValue = table.Rows[0][0].ToIntNN();
        }
         
        
        private void btnAta_Click(object sender, EventArgs e)
        {
            AppSession.DataManager.ExecuteNonQuery("SorumluAta", PayFlexId, cmbTip.Text, gle.EditValue.ToIntZero());
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        } 
    }
}
